package com.njym.java.security.app.rest;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.njym.java.security.app.biz.InvestGroupBiz;
import com.njym.java.security.app.entity.InvestGroup;
import com.njym.java.security.app.utils.RedisUtils;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.msg.TableResultResponse;
import com.njym.java.security.common.rest.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Controller
@RequestMapping("investGroup")
public class InvestGroupController extends BaseController<InvestGroupBiz,InvestGroup> {


    @RequestMapping(value = "/getWenJuanGroup", method = RequestMethod.GET)
    @ResponseBody
    public Object list(
            String name
    ){
        List<InvestGroup> investGroupList = baseBiz.queryList(name);
        if(investGroupList.size() == 0){
            return  new ObjectRestResponse<Object>().rel(true).data(1);
        } else {
            return new ObjectRestResponse<Object>().rel(true).data(investGroupList);
        }
    }

    /**
     * 通过id获取问卷小组信息
     * @param limit
     * @param page
     * @param groupId
     * @return
     */
    @RequestMapping(value = "/getGroup", method = RequestMethod.GET)
    @ResponseBody
    public Object list(@RequestParam(defaultValue = "10") int limit,
                       @RequestParam(defaultValue = "1")int page,
                       Integer groupId){
        Example example = new Example(InvestGroup.class);
        example.createCriteria().andEqualTo("deleted",0).andEqualTo("id",groupId);
        Page<Object> result = PageHelper.startPage(page, limit);
        baseBiz.selectByExample(example);
        return new TableResultResponse<Object>(result.getPages(),result.getResult());
    }
}